home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_100 / 132_01 / serio.c < prev    next >
Encoding:
Text File  |  1985-08-19  |  1.3 KB  |  71 lines

  1. /*
  2.     Program to provide serial i/o from the system on an SSM
  3. IO4 board.
  4. */
  5. #include    bdscio.h
  6. char    inbuf[BUFSIZ];
  7. #define    DATAB 0x23
  8. #define STATB 0x22
  9. #define DATAV    0x80
  10. #define RCVERR    0x70
  11. #define TBE    0x01    /* Transmitter buffer empty */
  12. #define DELAY    100    /* line delay */
  13. /*
  14.     program to dump an ascii file to a serial port
  15. */
  16. main(argc, argv)
  17. char    *argv[];
  18. {
  19. int fd;
  20. char    *p;
  21. char    c;
  22.  
  23.   if(argc >1) {
  24.     fd=fopen(argv[1],inbuf);
  25.     if(fd !=NULL) {
  26.         serout(0x0d);
  27.         serout(0x0A);
  28.         serout('S');
  29.         serout(0x0D);
  30.         serout(0x0A);
  31.         while((c=getc(inbuf)) !=CPMEOF) {
  32.             serout(c);
  33.         }
  34.         serout(0x0D);
  35.         serout(0x0A);
  36.         serout('X');
  37.         fclose(inbuf);
  38.     }
  39.     else printf("Cannot open file \n");
  40.   }
  41. }
  42. /*
  43.     serout outputs to the serial port
  44. */
  45. serout(ch)
  46. char ch;
  47. {
  48. int    t;
  49.     while((TBE & inp(STATB))==0); /* wait on xmt buff empty */
  50.     if(ch < 0x20) wait();
  51.     outp(DATAB,ch);
  52. }
  53. /*
  54.     serinp inputs a character from the port
  55. */
  56. serinp()
  57. {
  58. char    ch;
  59. while((DATAV && (ch = inp(STATB))) == 0);    /*wait on data available */
  60.     if((ch & RCVERR) == 0) return(inp(DATAB));
  61.     else {
  62.         ch=inp(DATAB);
  63.         return('?');
  64.          }
  65. }
  66. wait()
  67. {
  68. int    j;
  69.     for(j=0;j<=DELAY;j++);
  70. }
  71.